package net.jeanhwea.ex1;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class ScanURL {
	
	public void scan(String u) throws IOException {
		URL url = new URL(u);
		HttpURLConnection http = (HttpURLConnection) url.openConnection();
		
		int count = 0;
		String key, value;
		
		do{
			key = http.getHeaderFieldKey(count);
			value = http.getHeaderField(count);
			count++;
			if(value != null){
				if(key != null){
					System.out.println(value);
				} else {
					System.out.println(key + ": " + value);
				}
			}
		}while(value != null);
		
		http.disconnect();
		
	}

	public static void main(String[] args) {
		String url = "http://www.baidu.com";
		try {
			new ScanURL().scan(url);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
